package com.jk.lzy.controller;

import com.jk.*;
import com.jk.service.MovieInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;

/**
 * @Author: 梁展艺
 * @Description:  消费者
 * @Date: 2021/5/21 20:41
 * @param null
 * @Return:
 **/
@Controller
@RequestMapping("lzyConsumer")
public class MovieInfoController {
    @Autowired
    private MovieInfoService lzyUserService;
    /**
     * @Author: 梁展艺
     * @Description:  购票 影院信息回显
     * @Date: 2021/5/21 11:15
     * @param cinemaId
     * @Return: com.jk.CinemaBean
     **/
    @RequestMapping("chooseByCinemaId")
    @ResponseBody
    public CinemaBean chooseByCinemaId(Integer cinemaId){ // 传 影院的 id
        return lzyUserService.chooseByCinemaId(cinemaId);
    }
    /**
     * @Author: 梁展艺
     * @Description:  首页点击购票  展示影院详情
     * @Date: 2021/5/21 16:23
     * @param movieId
     * @Return: com.jk.MovieBean
     **/
    @RequestMapping("movieDetailsBy")
    public String movieDetailsBy(Integer movieId, Model model){
        MovieBean movieBean =  lzyUserService.movieDetailsBy(movieId);
        model.addAttribute("movieBean",movieBean);
        return "buyticket/index";
    }
    /**
     * @Author: 梁展艺
     * @Description: 购票 根据 市 查询 影院
     * @Date: 2021/5/21 20:33
     * @param cinema
     * @Return: java.util.List<com.jk.CinemaBean>
     **/
    @GetMapping("cinemaByCity")
    @ResponseBody
    public List<CinemaBean> cinemaByCity(CinemaBean cinema){
        return lzyUserService.cinemaByCity(cinema);
    }
    /**
     * @Author: 梁展艺
     * @Description:  根据影院查看电影
     * @Date: 2021/5/24 19:36
     * @param cinemaId
     * @Return: java.util.List<com.jk.MovieBean>
     **/
    @RequestMapping("movieByCinema")
    @ResponseBody
    public MovieBean movieByCinema(Integer movieId){
        return lzyUserService.movieByCinema(movieId);
    }
    /**
     * @Author: 梁展艺
     * @Description: 影院电影放映 安排
     * @Date: 2021/5/25 20:07
     * @param program
     * @Return: java.util.List<com.jk.ProgramBean>
     **/
    @RequestMapping("moviePlan")
    @ResponseBody
    public List<ProgramBean> moviePlan(ProgramBean program){
        return lzyUserService.moviePlan(program);
    }
    /**
     * @Author: 梁展艺
     * @Description:  选座 回显放映计划
     * @Date: 2021/5/26 11:27
     * @param programId
     * @Return: com.jk.ProgramBean
     **/
    @RequestMapping("programByprogramId")
    @ResponseBody
    public ProgramBean programByprogramId(Integer programId){
        return lzyUserService.programByprogramId(programId);
    }
    /**
     * @Author: 梁展艺
     * @Description: 座位描述
     * @Date: 2021/5/27 10:29
     * @param programId
     * @Return: com.jk.MovieHallBean
     **/
    @RequestMapping("seatInfo")
    @ResponseBody
    public HashMap seatInfo(Integer programId){
        return lzyUserService.seatInfo(programId);
    }
    /**
     * @Author: 梁展艺
     * @Description:  生成订单
     * @Date: 2021/5/28 21:29
     * @param programId
     * @Return: java.lang.String
     **/
    @RequestMapping("createOrder")
    @ResponseBody
    public OrderBean createOrder(Integer programId,String state,Double orderPrice,HttpSession session){
        UserBean user = (UserBean) session.getAttribute("user");
        OrderBean order = lzyUserService.createOrder(programId,state,orderPrice,user);
        return order;
    }
    @RequestMapping("buyTicketLogin")
    @ResponseBody
    public String buyTicketLogin(HttpSession session){
        UserBean user = (UserBean) session.getAttribute("user");
        if (user == null){
            return "请登录";
        }
        return "登录";
    }
}
